﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace InstantSpine.Core.MaterialModels
{
    /// <summary>
    /// A single sample of a uniaxial tension test
    /// </summary>
    /// <remarks>This data type is isomorphic to Tuple´2[double, double].
    /// The only reason for its existence is to enable automatic column
    /// generation by WPF's datagrid control </remarks>
    public class StressStrainPair : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private double stress;
        private double strain;

        // read/write for two-way binding
        /// <summary>
        /// Measured stress
        /// </summary>
        public double Stress {
            get { return stress; }
            set {
                if (stress != value) {
                    stress = value;
                    PropertyChanged.Raise(this);
                }
            }
        }

        // read/write for two-way binding
        /// <summary>
        /// Measured strain
        /// </summary>
        public double Strain {
            get { return strain; }
            set {
                if (strain != value) {
                    strain = value;
                    PropertyChanged.Raise(this);
                }
            }
        }

        // required so that user can add data rows
        // using the WPF data grid
        public StressStrainPair() { }

        public StressStrainPair(double stress, double strain) {
            this.stress = stress;
            this.strain = strain;
        }

        public static implicit operator StressStrainPair(Tuple<double, double> stressStrain) {            
            return new StressStrainPair(stressStrain.Item1, stressStrain.Item2);
        }
    }    
}
